using System;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

namespace OR.Lazarus.Library.DataTier.Source
{
   public class IntersectionDetail : OR.Lazarus.Library.DataTier.Source.Lazarus.IntersectionDetail
   {
		protected ProjectDetail m_Project;

		public ProjectDetail Project
		{
			get
			{
				return ( m_Project );
			}
			set
			{
				m_Project = value;
			}
		}

		public FieldDetail GetPKField()
		{
			FieldDetail v_oReturn	= null;
			FieldDetail	v_oDefault	= this.Project.DefaultSetting.Fields.GetPKField();
			FieldDetail	v_oInternal	= this.Fields.GetPKField();

			if ( v_oDefault == null )
			{
				v_oReturn = v_oInternal;
			}
			else
			{
				v_oReturn = v_oDefault;
			}

			return ( v_oReturn );
		}

		public void Initialize()
		{
			this.OnInitialize();
		}

		protected virtual void OnInitialize()
		{
			this.OnInitializeName();
		}

		protected virtual void OnInitializeName()
		{
			foreach ( ReferenceDetail vReference in this.References )
			{
				if ( String.IsNullOrEmpty( this.LogicalName ) )
				{
					this.LogicalName = this.Name;
				}

				if ( String.IsNullOrEmpty( this.FriendlyName ) )
				{
					this.FriendlyName = this.LogicalName;
				}

				if ( String.IsNullOrEmpty( vReference.Accessor ) )
				{
					vReference.Accessor = vReference.Name;
				}

				if ( String.IsNullOrEmpty( vReference.Alias ) )
				{
					vReference.Alias = vReference.Accessor.ToLower();
				}
			}
		}
	}
}
   